package com.collection;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.Objects;

public class HomeWork_3 {
    public static void main(String[] args) {
        ArrayList<Employ> arrayList=new ArrayList<Employ>();
        arrayList.add(new Employ("jackuiib",3000,new MyDate(2005,9,11)));
        arrayList.add(new Employ("mackhikfvi",5000,new MyDate(2004,10,1)));
        arrayList.add(new Employ("tom",4000,new MyDate(2005,3,20)));
      for(Employ employ:arrayList){
          System.out.println(employ);
      }
      arrayList.sort(new Comparator<Employ>() {
          @Override
          public int compare(Employ o1, Employ o2) {

              return o1.getName().length()-o2.getName().length();
          }
      });
        for(Employ employ:arrayList){
            System.out.println(employ);
        }


    }
}

class Employ {
    private String name;
    private double sal;
    private MyDate birthday;


    public Employ(String name, double sal, MyDate birthday) {
        this.name = name;
        this.sal = sal;
        this.birthday = birthday;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Employ employ = (Employ) o;
        return Double.compare(employ.sal, sal) == 0 && Objects.equals(name, employ.name) && Objects.equals(birthday, employ.birthday);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, sal, birthday);
    }

    @Override
    public String toString() {
        return "Employ{" +
                "name='" + name + '\'' +
                ", sal=" + sal +
                ", birthday=" + birthday +
                '}';
    }

    public double getSal() {
        return sal;
    }

    public void setSal(double sal) {
        this.sal = sal;
    }

    public MyDate getBirthday() {
        return birthday;
    }

    public void setBirthday(MyDate birthday) {
        this.birthday = birthday;
    }
}
class MyDate{
    private int year;
    private int month;
    private int day;

    public MyDate(int year, int month, int day) {
        this.year = year;
        this.month = month;
        this.day = day;
    }

    @Override
    public String toString() {
        return "MyDate{" +
                "year=" + year +
                ", month=" + month +
                ", day=" + day +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        MyDate myDate = (MyDate) o;
        return year == myDate.year && month == myDate.month && day == myDate.day;
    }

    @Override
    public int hashCode() {
        return Objects.hash(year, month, day);
    }
}
